package controller;

import entity.Cat;
import service.CatService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/cat")
public class CatController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*在进行主页页面跳转时，需要将数据库中的数据查询并传输到前端，前端再将这些数据展示出来*/
        CatService catService=new CatService();
        String sql="SELECT * FROM cat";
        List<Cat> catList=catService.getCat(sql);
        // 将查询到的数据传递到前端
        req.setAttribute("catList",catList);
        req.getRequestDispatcher("view/detail.jsp").forward(req,resp);
    }
}
